<?php
/**
 * [mm] Copyright (c) 2018/5/3
 * 评论mod
 */
defined('IN_IA') or exit('Access Denied');

/**
 * 回复评论
 * @param  int $jid        评论id
 * @param  string $content 评论的内容
 * @param  string $img     评论的图片
 * @return string          评论的详情
 */
function createJudgment($jid, $content, $img)
{
    $judgment_id = $jid;
    $content = $content;

    $data_content['judgment_id'] = $judgment_id;
    $data_content['content_id'] = date('Ymd').substr(time(), -5).substr(microtime(), 2, 5).sprintf('%02d', rand(0, 99));
    $data_content['content'] = $content;
    $data_content['update_time'] = TIMESTAMP;
    $data_content['who'] = 1;

    $addjudgment_content = pdo_insert('tg_judgment_content', $data_content);

    $goimages = $img;
    $goimages = array_reverse($goimages);
    foreach ($goimages as $key => $value) {
        $data2 = array('img_url' => $goimages[$key], 'content_id' => $data_content['content_id']);
        pdo_insert('tg_judgment_img', $data2);
    }
}

/**
 * 获取某一评论的所有回复
 * @param  int $id 评论id
 * @return array     所有评论回复
 */
function getJudgments($id)
{
    $judgments = pdo_getAll('tg_judgment_content', array('judgment_id' => $id));
    foreach ($judgments as $key => $value) {
        $img = pdo_get('tg_judgment_img', array('content_id' => $value['content_id']));
        $judgments[$key]['img'] = $img['img_url'];
    }
    return $judgments;
}
